package main

import (
	"fmt"
	"runtime"
	"time"
)

func main6() {
	fmt.Println("Gosched............................")
	go func(name string) {
		for i := 0; i < 2; i++ {
			fmt.Println("你好啊：", name)
		}

	}("liuche")

	for i := 0; i < 2; i++ {
		// 让出时间片
		runtime.Gosched()
		fmt.Println("hello main")
	}
	time.Sleep(200 * time.Millisecond)

	fmt.Println("Goexit.............................")
	go func() {
		defer fmt.Println("A.defer")
		func() {
			defer fmt.Println("B.defer")
			fmt.Println("B")
			runtime.Goexit()
			// 结束协程

		}()
		fmt.Println("A")
	}()
	time.Sleep(200 * time.Millisecond)

	fmt.Println("GOMAXPROCS.........................")
	runtime.GOMAXPROCS(2)
	go a()
	go b()
	time.Sleep(200 * time.Millisecond)
}

func a() {
	for i := 1; i < 10; i++ {
		fmt.Println("A:", i)
	}
}

func b() {
	for i := 1; i < 10; i++ {
		fmt.Println("B:", i)
	}
}
